const assertUtil = require('../util/assertUtil');
module.exports = {
  DATE_FORMAT: 'YYYY-MM-DD',
  DATE_TIME_FORMAT: 'YYYY-MM-DD H:mm:ss',
  PAGE_SIZE: 10,
  assertUtil,
  throw(msg, errno) {
    const err = new Error(msg);
    err.errno = errno || 0;
    err.isCustom = true;
    throw err;
  },
  camelResult(arrOrObj) {
    if (Array.isArray(arrOrObj)) {
      const rt = [];
      arrOrObj.forEach(item => {
        rt.push(this.camelObject(item));
      });
      return rt;
    } else if (typeof arrOrObj === 'object') {
      return this.camelObject(arrOrObj);
    }
    return think.camelCase(arrOrObj);
  },
  camelObject(object) {
    const rt = {};
    Object.keys(object).forEach(key => {
      rt[think.camelCase(key)] = object[key];
    });
    return rt;
  }
};
